package mz.mobileservices.uem;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
//import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

public class NotificacaoService extends Service
{
	private NotificationManager mNotificationManager;
	private int SIMPLE_NOTFICATION_ID;
	
	public IBinder onBind(Intent arg0) 
	{
		return null;
	}
	
	@Override
	public void onCreate() 
	{
		Log.e("ME", "Service Created");
	}

	@Override
	public void onDestroy() 
	{
		Log.e("ME", "Service Stopped");
	}
	
	@Override
	public void onStart(Intent i, int startid) 
	{
		String msg = ReceiveSMS.message.toString();
		String nr = ReceiveSMS.number.toString();
		
		if(nr!=null && msg!=null)
		{	
    		 mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

    		 Notification notifyDetails = new Notification(R.drawable.android,"MobileServices Alert!",System.currentTimeMillis());

    		 long[] vibrate = {100,100,200,300};
    		 notifyDetails.vibrate = vibrate;
    		 notifyDetails.defaults = Notification.DEFAULT_ALL;
    		 
    		 String contentTitle = "Resposta de: "+ReceiveSMS.number.toString();
    	     String contentText = "Click para ver a resposta ao pedido..";
    		 
    		 Intent notifyIntent = new Intent(getApplicationContext(), Resposta.class);
    		 notifyIntent.putExtra("resposta", msg);

    		 PendingIntent intent = PendingIntent.getActivity(this, 0,notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);

    		 notifyDetails.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, intent);
    		 
    		 notifyDetails.flags = Notification.FLAG_AUTO_CANCEL;
    		 mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
    		 
    		 Log.e("ME","Service started");
		}
	}
}